package com.zenchn.service.impl;


import com.zenchn.dao.TSysOauthCodeMapper;
import com.zenchn.dynamic.TSysOauthCodeDynamicMapper;
import com.zenchn.generic.GenericDao;
import com.zenchn.generic.GenericServiceImpl;
import com.zenchn.model.TSysOauthCode;
import com.zenchn.model.TSysOauthCodeExample;
import com.zenchn.service.OauthCodeService;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import static org.mybatis.dynamic.sql.SqlBuilder.*;
import static com.zenchn.dynamic.TSysOauthCodeDynamicSqlSupport.*;

/**
 * 授权编码 业务实现类
 *
 * @author dingxinfa
 * @date 2020-04-16
 **/
@Service
@Transactional(rollbackFor = Exception.class)
public class OauthCodeServiceImpl extends GenericServiceImpl<TSysOauthCode, String, TSysOauthCodeExample> implements OauthCodeService {

	@Resource
	private TSysOauthCodeMapper oauthCodeMapper;
	@Resource
	private TSysOauthCodeDynamicMapper oauthCodeDynamicMapper;

	@Override
	public GenericDao<TSysOauthCode, String, TSysOauthCodeExample> getDao() {
		return oauthCodeMapper;
	}

	@Override
	public boolean existByAuthCode(String clientId, String authCode) {
		TSysOauthCodeExample example=new TSysOauthCodeExample();
		example.createCriteria().andClientIdEqualTo(clientId).andAuthCodeEqualTo(authCode);
		return oauthCodeMapper.selectByExample(example).size() > 0;
	}

	@Override
	public TSysOauthCode selectByAuthCode(String clientId, String authCode) {
		TSysOauthCodeExample example=new TSysOauthCodeExample();
		example.createCriteria().andClientIdEqualTo(clientId).andAuthCodeEqualTo(authCode);
		List<TSysOauthCode> oauthCodeList=oauthCodeMapper.selectByExample(example);
		if(oauthCodeList.size()>0){
			return oauthCodeList.get(0);
		}
		return null;
	}


}
